package restful.servlet.sample;

public class OverrideHttpMethod {

	private final String result;

	public OverrideHttpMethod(final String httpMethod, final String _METHOD) {
		result = choseBetween(httpMethod, _METHOD);
	}

	private String choseBetween(final String httpMethod, final String _METHOD) {
		if (notPOST(httpMethod)) return httpMethod;
		if (emptyOrNull(_METHOD)) return httpMethod;
		return _METHOD;
	}

	private boolean emptyOrNull(final String _METHOD) {
		return null == _METHOD  || "".equals(_METHOD);
	}

	private boolean notPOST(final String httpMethod) {
		return !httpMethod.equalsIgnoreCase("POST");
	}

	@Override
	public String toString() {
		return result;
	}

}
